clear 

* set directory 
* cd "directory"

* set paths
global datafolder "data"
global outputfolder "output"

********************************************************************************
*			Figure 4: Actual rate and breakeven rate
********************************************************************************
	use "$datafolder\maindata.dta", clear
	
	keep if datem >= 660
	
	gen diag_line = _n
	
	twoway (scatter actual_rate theoretical_rate [aweight=balance] ///
	if type==1, yscale(range(0 25)) ylabel(0(5)25, angle(horizontal)) ///
	graphregion(color(white)) color(black) mfcolor(none) jitter(3)  ) ///
	(scatter actual_rate theoretical_rate [aweight=balance] ///
	if type==2, color(brown) mfcolor(none) /// 
	legend(pos(10) ring(0) order(1 2) lab(1 "Term Loans") ///
	lab(2 "Credit Lines") region(lcolor(white) fcolor(none))  ) )  ///
	(line diag_line diag_line if diag_line<25, color("red") lpattern("--") ///
	xtitle("Breakeven Rate") ytitle("Actual Rate") )	///
	(lfit actual_rate theoretical_rate, color(blue)  ) 
		
	graph export "$outputfolder\figure_4.pdf", as(pdf) replace
	graph export "$outputfolder\figure_4.png", as(png) replace